<template>
  <div>
    <!-- 表格 -->
    <div>
      <el-table :data="list" style="width: 100%" stripe @selection-change="selectChange">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column label="图片" align="center">
          <template slot-scope="scope">
            <!-- eslint-disable-next-line -->
            <l-pic :picurl="scope.row.avatar" :size="{width:40,height:40}" :disdel="false" :disview="false"/>
          </template>
        </el-table-column>
        <el-table-column prop="nickname" label="团员名称" align="center"></el-table-column>
        <el-table-column prop="phone" label="团员手机号" align="center"></el-table-column>
      </el-table>
    </div>

    <!-- 分页 -->
    <div style="text-align:right;margin:15px 15px">
      <el-pagination class="page"
        background
        layout="total, prev, pager, next, jumper"
        :total="count"
        :page-size="10"
        :current-page="page"
        @size-change="changePage"
        @current-change="changePage">
      </el-pagination>
    </div>

    <!-- 提交 -->
    <div style="text-align:center;margin-top:25px">
      <el-button type="primary" style="padding:8px 20px" @click="submit">保 存</el-button>
    </div>
  </div>
</template>

<script>
import LPic from '@/components/lPic'
import { getTuanLeagueMemberList, putTuanLeagueMember } from '@/api/customers'

export default {
  name: 'addWriteOff',
  components: {
    LPic
  },
  props: {
    tuanId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      page: 1,
      count: 1,
      list: [],
      selectGoods: [],
    }
  },
  mounted() {
    console.log(this.tuanId)
    this.getTuanLeagueMemberList();
  },
  methods: {
    /**
     * 获取旗下团员列表
     */
    getTuanLeagueMemberList() {
      const params = {
        key: this.$store.state.app.activeApp.saa_key,
        page: this.page,
        limit: 10,
        id: this.tuanId,
        type: 0
      };
      getTuanLeagueMemberList(params).then(res => {
        if(res.status === 200){
          this.list = res.data;
          this.count = parseInt(res.count);
        }else if(res.status === 204){
          this.list = [];
          this.count = 1;
        }else{
          this.$message.error(res.message);
        }
      })
    },
    /**
     * 翻页
     */
    changePage(page) {
      this.page = page;
      this.getTuanLeagueMemberList();
    },
    /**
     * 修改选择
     */
    selectChange(select) {
      this.selectGoods = select;
    },
    /**
     * 提交
     */
    submit() {
      const params = { is_verify: '1', key: this.$store.state.app.activeApp.saa_key };
      this.selectGoods.forEach(item => {
        params.id.push(item.id);
      });
      putTuanLeagueMember(params).then(res => {
        if(res.status === 200){
          this.$emit('success');
        }else{
          this.$message.error(res.message);
        }
      })
    }
  },
}
</script>